// import com.alibaba.druid.sql.ast.SQLExpr_ptr;
// import com.alibaba.druid.sql.ast.SQLName_ptr;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLOpenStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../expr/SQLIdentifierExpr.h"
#include "../../../utils/listTran.h"

SQLOpenStatement::SQLOpenStatement()
{
  columns = std::make_shared<std::list<SQLName_ptr>>();
  using_ = std::make_shared<std::list<SQLExpr_ptr>>();
}

SQLName_ptr SQLOpenStatement::getCursorName()
{
  return cursorName;
}

void SQLOpenStatement::setCursorName(string_ptr cursorName)
{
  setCursorName(SQLIdentifierExpr_ptr(new SQLIdentifierExpr(cursorName)));
}

void SQLOpenStatement::setCursorName(SQLName_ptr cursorName)
{
  if (cursorName != nullptr)
  {
    cursorName->setParent(SharedObject(SQLOpenStatement));
  }
  this->cursorName = cursorName;
}

// @Override
void SQLOpenStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLOpenStatement)))
  {
    acceptChild(visitor, cursorName);
    acceptChild(visitor, forExpr);
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLName, SQLObject>(columns);
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(SQLOpenStatement));
}

SQLExpr_ptr SQLOpenStatement::getFor()
{
  return forExpr;
}

void SQLOpenStatement::setFor(SQLExpr_ptr forExpr)
{
  if (forExpr != nullptr)
  {
    forExpr->setParent(SharedObject(SQLOpenStatement));
  }
  this->forExpr = forExpr;
}

SQLName_list_ptr SQLOpenStatement::getColumns()
{
  return columns;
}

SQLExpr_list_ptr SQLOpenStatement::getUsing()
{
  return using_;
}
